Package com.graphics

Source Code of com.graphics.ConnectingBox

package com.graphics;
/**
* @author Dror
*
* email: gumjum.o.o@gmail.com
*
*/

import java.awt.Color;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.math.Quat;
import com.math.Vector;


public class ConnectingBox extends Box{

  boolean []isBridged;
 
  public ConnectingBox(Camera cam,Vector dim,Vector pos,Quat rot,Color color) {//Vector rot
    super(cam, dim, pos, rot,color);
   
  }
 
  public void build(){
    for(int i = 0;i<points_num;i++)
      points[i] = new Vector();
   
    isBridged = new boolean[points_num];
    for(int i = 0;i<points_num;i++){
      isBridged[i] = false;
    }
   
    bridg();
   
  }
  public void bridgPoint(int i,Vector p){
    this.points[i] = p;
    this.isBridged[i] = true;
    this.bridg();
  }
 
  public void rebuild(){
    if(!isBridged[0])
      points[0].set(-d.x,+d.y,-d.z);
    if(!isBridged[1])
      points[1].set(+d.x,+d.y,-d.z);
    if(!isBridged[2])
      points[2].set(+d.x,+d.y,+d.z);
    if(!isBridged[3])
      points[3].set(-d.x,+d.y,+d.z);
    if(!isBridged[4])
      points[4].set(-d.x,-d.y,-d.z);
    if(!isBridged[5])
      points[5].set(+d.x,-d.y,-d.z);
    if(!isBridged[6])
      points[6].set(+d.x,-d.y,+d.z);
    if(!isBridged[7])
      points[7].set(-d.x,-d.y,+d.z);
   
    for(int i=0;i<8;i++){
      if(!isBridged[i]){
        points[i].transformation(r,p);
        points[i].reverseTransformation(cam.r, cam.p);
      }
    }
   
    tmp.reverseTransformation(cam.r, cam.p,p);
    compare_z = (int)(tmp.z);
   
  }
 
  public void toXML(Document d,Element e){
   
    Element position   = d.createElement("Position");
    position.setTextContent(this.p.toString());
    Element rotation   = d.createElement("Rotation");
    rotation.setTextContent(this.r.toString());
    Element dimmention  = d.createElement("Dimmention");
    dimmention.setTextContent(this.d.toString());
    Element colo     = d.createElement("Color");
    colo.setTextContent(""+this.def_color.getRGB());
    Element box     = d.createElement("ConnectingBox");
   
    box.appendChild(position   );
    box.appendChild(rotation   );
    box.appendChild(dimmention  );
    box.appendChild(colo     );
    box.appendChild(box     );
   
    e.appendChild(box);
  }
 
  public Element toXML(Document d){
   
    Element position   = d.createElement("Position");
    position.setTextContent(this.p.toString());
    Element rotation   = d.createElement("Rotation");
    rotation.setTextContent(this.r.toString());
    Element dimmention  = d.createElement("Dimmention");
    dimmention.setTextContent(this.d.toString());
    Element colo     = d.createElement("Color");
    colo.setTextContent(""+this.def_color.getRGB());
   
    Element box     = d.createElement("ConnectingBox");
   
    box.appendChild(position   );
    box.appendChild(rotation   );
    box.appendChild(dimmention  );
    box.appendChild(colo     );
   
    return box;
  }
 
  public static ConnectingBox fromXML(Element e, Camera cam){

    Color color =  new Color(Integer.parseInt(e.getElementsByTagName("Color").item(0).getTextContent()));
    Vector d = Vector.parseVector(e.getElementsByTagName("Dimmention").item(0).getTextContent());
    Vector p = Vector.parseVector(e.getElementsByTagName("Position").item(0).getTextContent());
    Quat r = Quat.parseQuat(e.getElementsByTagName("Rotation").item(0).getTextContent());
   
    return new ConnectingBox(cam,d,p,r,color);
  }
 
}
TOP

Related Classes of com.graphics.ConnectingBox

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.